# -*- coding:utf8-*-
import os
import time
from multiprocessing import Pool


def foo(x):
    print('Run task %s (pid:%s).... ' % (x, os.getpid()))
    time.sleep(2)
    print('Task %s result is: %s' % (x, x * x))


if __name__ == '__main__':
    print('Parent process %s.' % os.getpid())
    p = Pool(4)
    for i in range(5):
        p.apply_async(foo, args=(i,))
    print('Waiting for all subprocesses done...')
    p.close()
    p.join()
    print('All subprocesses done.')
